package xyz.yuzegod.megawalls.classes.normal.shaman;

import org.bukkit.Material;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.CollectSkill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ItemUtils;
import xyz.yuzegod.megawalls.util.PlayerUtils;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class FourthSkill extends CollectSkill
{
    public FourthSkill(final Classes classes) {
        super("灵力开采", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.2;
            }
            case 2: {
                return 0.4;
            }
            case 3: {
                return 0.6;
            }
            default: {
                return 0.2;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        lore.add(" §8▪ §7挖铁矿时有§a" + StringUtils.percent(this.getAttribute(level)) + "§7几率。");
        lore.add("   §7掉落一根原木和一块煤炭。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill4Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill4Level();
    }
    
    @Override
    public void onBlockBreak(final KitStatsContainer kitStats, final BlockBreakEvent e) {
        if (ItemUtils.matchMaterial(e.getBlock(),Material.IRON_ORE) && MegaWalls.getRandom().nextInt(200) <= this.getAttribute(kitStats.getSkill4Level()) * 100.0) {
            PlayerUtils.gatheringItem(new ItemStack(Material.LOG),e);
            PlayerUtils.gatheringItem(new ItemStack(Material.COAL),e);
        }
    }
}
